package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.getBuyerInviteCodeInfoBean;
import com.ymatou.iapi.godmch.service.getBuyerInviteCodeInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.mapping.godmch.buyer_invite_codeMapper;
import com.ymttest.database.model.godmch.buyer_invite_code;
import com.ymttest.database.model.godmch.buyer_invite_codeExample;
import com.ymttest.database.sqlwapper.godmch.buyer_invite_codeWapper;
/**
*查询买家邀请码
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getBuyerInviteCodeInfo{
	private static getBuyerInviteCodeInfoBean bean;
	private static getBuyerInviteCodeInfoCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询买家邀请码");
	}

	@Before
	public void caseUp() {
		bean=new getBuyerInviteCodeInfoBean();
		call=new getBuyerInviteCodeInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify() throws InterruptedException {
		//验证
		boolean isCs=false;
		if(bean.getCsId()!=null && bean.getCsId()!=0) isCs=true;
		else isCs=false;
			
		buyer_invite_codeExample example=new buyer_invite_codeExample();
		example.createCriteria().andCodeStatusEqualTo(0).andUserIdEqualTo(isCs==true?bean.getCsId():bean.getMchId());
		buyer_invite_codeWapper codeMapper=new buyer_invite_codeWapper();
		buyer_invite_code model=codeMapper.selectByExample(example).get(0);
		
		Logger.verifyEquals("200", call.getStatusCode1(), "验证code");
		if(isCs==true)
			Logger.verifyEquals(model.getUserId(), call.getCsId(), "验证CsId");
		else
			Logger.verifyEquals(model.getUserId(), call.getMchId(), "验证mchId");
		
		Logger.verifyEquals(model.getInviteCode(), call.getInviteCode(), "验证inviteCode");

	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_001() {
		Logger.start(true,"查询买家邀请码-验证mchId与csId都传,返回csId的邀请码-1：主商户");
		try {
		    //若mchId与csId都传，以csId为主
			bean.setMchId(500011975);
			//bean.setCsId(501073646);
			call.setData(bean);
			call.callService();			
			//验证
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_001_1() {
		Logger.start(true,"查询买家邀请码-验证mchId与csId都传,返回csId的邀请码-2：客服");
		try {
		    //若mchId与csId都传，以csId为主
			
			bean.setMchId(500041475);
			bean.setCsId(501073646);
			call.setData(bean);
			call.callService();			
			//验证
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_001_2() {
		Logger.start(true,"查询买家邀请码-验证mchId与csId都传,返回csId的邀请码-3 - 分销员（分销机构）");
		try {
		    //若mchId与csId都传，以csId为主
			
			bean.setMchId(198411141);
			//bean.setCsId(501073646);
			call.setData(bean);
			call.callService();			
			//验证
			
			buyer_invite_codeExample example=new buyer_invite_codeExample();
			example.createCriteria().andCodeStatusEqualTo(0).andUserIdEqualTo(bean.getMchId());
			buyer_invite_codeWapper codeMapper=new buyer_invite_codeWapper();
			buyer_invite_code model=codeMapper.selectByExample(example).get(0);
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证code");
		   // Logger.verifyEquals(model.getUserId(), call.getCsId(), "验证CsId");
			Logger.verifyEquals(model.getInviteCode(), call.getInviteCode(), "验证inviteCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_002() {
		Logger.start(true,"查询买家邀请码-验证只传mchId,返回mchId的邀请码");
		try {
		    //若mchId与csId都传，以csId为主
			
			bean.setMchId(501128737);
			//bean.setCsId(501128736);
			call.setData(bean);
			call.callService();			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_003() {
		Logger.start(true,"查询买家邀请码-验证只传mchId、csId、inviteCode 都不为空,返回mchId的邀请码");
		try {
		    //若mchId与csId都传，以csId为主
			
			bean.setMchId(501431048);
			bean.setCsId(501431050);
			bean.setInviteCode("HJNR");
			call.setData(bean);
			call.callService();			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_004() {
		Logger.start(true,"查询买家邀请码-验证只传mchId、csId、inviteCode都不为空,其中csId与 inviteCode关系不一致， 返回mchId的邀请码");
		try {
		    //若mchId与csId都传，以csId为主
			
			bean.setMchId(3383);
			bean.setCsId(500364666);
			bean.setInviteCode("50036466611");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_004_1() {
		Logger.start(true,"查询买家邀请码-验证只传mchId、csId,其中csId对应的buyer_invite_code表中的userType=1， 返回mchId的邀请码");
		try {
		    //buyer_invite_code表中的userType=1 表示是商户，2表示是客服
			bean.setMchId(3383);
			bean.setCsId(500304277);
			bean.setInviteCode("50036466611");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_005() {
		Logger.start(true,"查询买家邀请码-验证只传csId,返回MchId");
		try {
			
			//bean.setMchId(3383);
			bean.setCsId(501431050);
			call.setData(bean);
			call.callService();			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBuyerInviteCodeInfo_006() {
		Logger.start(true,"查询买家邀请码-验证mchId、csId、inviteCode同时为空,返回失败");
		try {
			
			//bean.setMchId(3383);
			//bean.setCsId(500364666);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("500", call.getStatusCode1(), "验证code");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
}